package com.global.college.ui.activity;

import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;

import com.gauravk.bubblenavigation.BubbleNavigationLinearView;
import com.gauravk.bubblenavigation.listener.BubbleNavigationChangeListener;
import com.global.college.R;
import com.global.college.adapter.ScreenSlidePagerAdapter;
import com.global.college.base.BaseActivity;
import com.global.college.base.baselist.HsScrollViewPagerAdapter;
import com.global.college.ui.fragment.home.HomeFragment;
import com.global.college.ui.fragment.lesson.HomeCourseFragment;
import com.global.college.ui.fragment.mine.MineFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

/**
 * Author by xuyangsheng,  Date on 2024/7/15.
 * Explain：
 */
public class BottomBarActivity extends BaseActivity {

    private ArrayList<Fragment> fragments;
    private HomeFragment homeFragment;
    private HomeCourseFragment homeCourseFragment;
    private MineFragment mineFragment;
    private static final String HOME_KEY = "homePageFragment";
    private static final String MALL_KEY = "homeMallFragment";
    private static final String MINE_KEY = "homeMineFragment";
    private ScreenSlidePagerAdapter pagerAdapter;

    @Override
    public int getContentViewId() {
        return R.layout.activity_bottom_bar;
    }

    @Override
    public void onCreateNew(Bundle savedInstanceState) {

/*        fragments = new ArrayList<Fragment>();

        try {
            if (savedInstanceState != null) {
//                获取保存的fragment  没有的话返回null
                homeFragment = (HomeFragment) getSupportFragmentManager().getFragment(savedInstanceState, HOME_KEY);
                homeCourseFragment = (HomeCourseFragment) getSupportFragmentManager().getFragment(savedInstanceState, MALL_KEY);
                mineFragment = (MineFragment) getSupportFragmentManager().getFragment(savedInstanceState, MINE_KEY);


                addToList(homeFragment);
                addToList(homeCourseFragment);
                addToList(mineFragment);
                addToList(mineFragment);
                addToList(mineFragment);
            } else {
                homeFragment = new HomeFragment();
                homeCourseFragment = new HomeCourseFragment();
                mineFragment = new MineFragment();
                fragments.add(homeFragment);
                fragments.add(homeCourseFragment);
                fragments.add(mineFragment);
                fragments.add(mineFragment);
                fragments.add(mineFragment);
            }
            pagerAdapter =new ScreenSlidePagerAdapter(fragments, getSupportFragmentManager());
        } catch (Exception e) {
            e.printStackTrace();
        }

        final BubbleNavigationLinearView bubbleNavigationLinearView = findViewById(R.id.bottom_navigation_view_linear);

        bubbleNavigationLinearView.setBadgeValue(0, "40");
        bubbleNavigationLinearView.setBadgeValue(1, null); //invisible badge
        bubbleNavigationLinearView.setBadgeValue(2, "7");
        bubbleNavigationLinearView.setBadgeValue(3, "2");
        bubbleNavigationLinearView.setBadgeValue(4, ""); //empty badge

        final ViewPager viewPager = findViewById(R.id.view_pager);
        viewPager.setAdapter(pagerAdapter);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                bubbleNavigationLinearView.setCurrentActiveItem(i);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });


        bubbleNavigationLinearView.setNavigationChangeListener(new BubbleNavigationChangeListener() {
            @Override
            public void onNavigationChanged(View view, int position) {
                viewPager.setCurrentItem(position, true);
            }
        });*/

    }

    @Override
    public void getInitData() {

    }


    private void addToList(Fragment fragment) {
        if (fragment != null) {
            fragments.add(fragment);
        }
    }


}
